package com.thug.engine;

import java.util.ArrayList;

public class EntityManagers {

	public ArrayList<EntityManager> mEntityManagers;
	private final static EntityManagers mInstance = new EntityManagers();
	
	private EntityManagers() {
		mEntityManagers = new ArrayList<EntityManager>();
	}
	
	public static EntityManagers getInstance() { return mInstance; }
	
	public void registerEntityManager(EntityManager manager) {
		mEntityManagers.add(manager);
	}
	
	public void unRegisterEntityManager(EntityManager manager) {
		mEntityManagers.remove(manager);
	}
	
	public void updateManagers(float elapsedTime) {
		for(EntityManager manager : mEntityManagers) {
			manager.update(elapsedTime);
		}
	}
	
	public void onLoadManagers() {
		for(EntityManager manager : mEntityManagers) {
			manager.onLoad();
		}
	}
	
	public void onDestroyManagers() {
		for(EntityManager manager : mEntityManagers) {
			manager.onDestroy();
		}
	}
	
	public ArrayList<EntityManager> getEntityManager() {
		return mEntityManagers;
	}
	
	
	public EntityManager getEntityManager(Class cls) {
		for(int i = 0; i < mEntityManagers.size(); i++) {
			EntityManager mgr = mEntityManagers.get(i);
			if(mgr.getClass().isInstance(cls)){
				return mgr;
			}
		}
		return null;
	}
	
}
